﻿using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;

namespace CRM.Infrastructure.Tools
{
    public class JWTUtil
    {
        public static string EnJwt(Claim[] claims, string secretKey, string issuer)
        {
            var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secretKey));
            var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
            var jwt = new JwtSecurityToken(
                issuer: issuer,
                audience: issuer,
                claims: claims,
                expires: DateTime.Now.AddMinutes(60 * 24), //token 
                signingCredentials: creds);
            var token = new JwtSecurityTokenHandler().WriteToken(jwt);

            return token;
        }
    }
}
